﻿using Dapper;
using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TR.Domain.Entity.rbac_QXGL;
using TR.Domain.Repository.rbac_QXGL;

namespace TR.EFCore.Repository.rbac_QXGL
{
    public class qxRepository:IqxRepository
    {
        private readonly MyContext myContext;
        public qxRepository(MyContext myContext) 
        {
            this.myContext = myContext;
        }

        //侧栏

        public async Task<List<CeBianlan>> CeBianlanSelectAsync(string jid)
        {
            using (SqlConnection connection = new SqlConnection(myContext.conStr))
            {
                string sql = $@"select  qx.u_juriid,u_jurname,u_juraddress,u_jurpid,U_rolesiD
                                from rbac_RolesJurisdiction as jsqx
                                inner join rbac_Jurisdiction as qx
                                on qx.u_juriid=jsqx.U_juriiD
                                where U_rolesiD={jid} and u_jurpid=0
                                order by qx.U_juriiD asc";
                List<CeBianlan> list = (List<CeBianlan>)await connection.QueryAsync<CeBianlan>(sql);
                foreach (CeBianlan item in list)
                {
                    string sql1 = $@"select  qx.u_juriid,u_jurname,u_juraddress,u_jurpid,U_rolesiD
                                from rbac_RolesJurisdiction as jsqx
                                inner join rbac_Jurisdiction as qx
                                on qx.u_juriid=jsqx.U_juriiD
                                where U_rolesiD={jid} and u_jurpid={item.u_juriid}
                                order by qx.U_juriiD asc";
                    item.ulist = (List<CeBianlan>)await connection.QueryAsync<CeBianlan>(sql1);
                }
                return list;
            }
        }
    }
}
